<?php
class RateableFieldsController extends AppController
{
	var $name = 'RateableFields';
	
	function admin_delete($id = null,$listing_type_id = null)
	{
		$data = $this->RateableField->findById($id);
		if(empty($data))
		{
			$this->errorMsg(__('Invalid URL!'));
			$this->redirect($this->referer());
		}
		
		$countRateableFields = $this->RateableField->find('count',array('conditions'=>array('listing_type_id'=>$listing_type_id)));
		
		if($countRateableFields == 1)
		{
			$this->errorMsg(__('This field could not be deleted!'));
			$this->redirect($this->referer());			
		}
		
		if($this->RateableField->del($id))
		{
			$this->successMsg(__('Field deleted successfully.'));
			
		}else
		{
			$this->errorMsg(__('Field could not be deleted.'));
		}
		$this->redirect($this->referer());
		
	}
}
?>